import {defineStore} from 'pinia'
import {type ThemeState} from '@/store/interface'

const defaultPrimary = import.meta.env.VITE_DEFAULT_PRIMARY

const useThemeStore = defineStore('theme', {
	state: (): ThemeState => {
		return {
			layout: 'vertical', // 布局切换 ==>  纵向：vertical | 经典：classic | 横向：transverse | 分栏：columns
			isDark: false, // 深色模式
			isGrey: false, // 灰色模式
			isWeak: false, // 色弱模式
			isCollapse: false, // 折叠菜单
			breadcrumb: true, // 面包屑
			breadcrumbIcon: false, // 面包屑导航图标
			tabs: true, // 标签页
			tabsIcon: true, // 标签页图标
			fullScreen: false, // 当前页是否全屏
			assemblySize: 'small', // // element组件大小
			assemblySizeShow: false, // element组件大小是否显示
			primary: defaultPrimary // 全局主题颜色
		}
	},
	getters: {
		getLayout: state => state.layout
	},
	actions: {
		setLayout(layout: string) {
			this.layout = layout
		},
		setCollapse(flag: boolean) {
			this.isCollapse = flag
		},
		setFullScreen(flag: boolean) {
			this.fullScreen = flag
		},
		setAssemblySizeSize(assemblySize: string) {
			this.assemblySize = assemblySize
		},
		setPrimary(val: string) {
			this.primary = val
		},
		setWeakOrGrey(key: 'isGrey' | 'isWeak', flag: boolean) {
			this[key] = flag
		}
	},
	persist: true // 所有数据持久化
})

export default useThemeStore
